import { Slide } from '@libs/db/models/slide.model';
import { Controller, Get, Param } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { ModelType } from '@typegoose/typegoose/lib/types';
import { InjectModel } from 'nestjs-typegoose';

@ApiTags('轮播图接口')
@Controller('slides')
export class SlidesController {
  constructor(
    @InjectModel(Slide) private readonly SlideMode: ModelType<Slide>
  ){}


  // 获取全部轮播图
  @Get()
  @ApiOperation({summary: '获取全部轮播图'})
  async selectAll() {
    return await this.SlideMode.find();
  }

  // 接收轮播图的标签参数，首页的为 index，其他页的之后再规定
  @Get(':tab')
  @ApiOperation({summary: '获取对应页面的轮播图,请求需携带标识，如： 首页为 index'})
  async selectList(@Param('tab') tab: string) {
    console.log(tab)
    const data = await this.SlideMode.find({classification: tab}).populate('article_id');
    return data;
  }
}
